const jwt = require('jsonwebtoken');

const SECRET = 'eyJzZWNyZXQiOiAiTXh3NFc0eURkU1R0RjZ1RzYxQmx4Z0U0R2FYcXgyWUNQbEZQaXNVZyJ9';

// 生成 token
function sign(payload, expiresIn = '2h') {
  return jwt.sign(payload, SECRET, { expiresIn });
}

// 验证 token
function verify(token) {
  try {
    return jwt.verify(token, SECRET);
  } catch (err) {
    return null;
  }
}

module.exports = { sign, verify };
